﻿var action_self_view = "/area/query/self.do";
var allCity="/area/query/selfCity.do";					 //查询所有城市接口
var countyList="/area/query/county.do";//获取区县信息

var city_html =
    '<label class="ml5">地市选择:'
    + '<select class="easyui-combobox" name="citySelect"  id="citySelect" style="width: 100px;"></select>'
    + '</label>';
var county_html =
    '<label class="ml5">区县选择:'
    +'<select name="countySelect"  id="countySelect" style="width: 150px;" class="easyui-combobox" ></select>'
    +'</label>';

var page_level="";

//------------------------------------------------------------------菜单 start-------------------------------------------------------------
//获取用户所拥有的二级下拉列表菜单
function loadAreaView(){
    $.getJSON(action_self_view, function (json) {

        var code = json.code;
        if(code!=200){
        	alert("网络不好啊！");
        	return;
		}

        var data = json.data;
        var level = data.level;
        if(level === null){
            alert("用户权限配置不合理，请联系系统管理员！");
            return;
		}
        page_level = level;

        //画页面
		//根据不同的用户权限，控制用户页面显示几级菜单
        if(level=="province"||level=="city"){
            $("#insert_html").html(city_html+county_html);
            loadCombox();
        }else if(level=="county"){
            $("#insert_html").html(county_html);

			//加载区县(只有区县权限的用户)下拉列表
            loadCounty(allCity, null);
        }
    }, "json");
}

//加载地市下拉列表
function loadCombox(){
	$.getJSON(allCity, function (json) {
		$('#citySelect').combobox({    
			data:json.data,
		    valueField:'id',    
		    textField:'name',
		    onLoadSuccess: function () {
				var a = $('#citySelect').combobox('getData');
				if (a.length > 0) {
					$('#citySelect').combobox('select', a[0].id);
				}
			},
			onSelect: function(rec){
				loadCounty(countyList, rec.id);
	        }
		});  
	}, "json");
}

//加载区县下拉列表
function loadCounty(action_url, id){
	$.get(action_url, {"areaid":id},function (json) {
		$('#countySelect').combobox({
			async:false,
			method:'GET',
			data:json.data,
			editable:true,
			valueField:'id',
			textField:'name',
			onLoadSuccess: function () {
				var a = $('#countySelect').combobox('getData');
				if (a.length > 0) {
					$('#countySelect').combobox('select', a[0].id);
				}
			},
			onSelect:function (city) {
				 query(3);
			}
		})
	}, "json");
}
//------------------------------------------------------------------菜单 end-------------------------------------------------------------

$(function(){
	loadGRID();
	var iHeight = document.documentElement.clientHeight;
	var iWidth = document.documentElement.offsetWidth;
	$("#chart_city").width(iWidth*0.5-50+'px');
	$("#chart_city").height(iHeight-140+'px');
	loadYear(3);
	loadAreaView();
	loadForm(3);
});
